<template>
	<view class="store-team">
		<block v-if="show">
			<view class="store-team-list">
				<pt-design-item v-for="(data,index) in storeTeam" :key="index" :item="data"
					@click="goTeamInfo(data.store_stylist_id)"></pt-design-item>
			</view>
			<pt-loading-more v-if="isLoading"></pt-loading-more>
			<pt-nomore v-if="noMore && storeTeam.length"></pt-nomore>
			<pt-nothing text="暂无设计师" v-if="noMore && !storeTeam.length" :fixed="true"
				icon="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/nothing.png?v=1">
			</pt-nothing>
		</block>
		<pt-loading></pt-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				storeTeam: [],
				page: 0,
				noMore: false,
				isLoading: false
			};
		},
		onLoad(options) {
			if (options.parent_id) {
				uni.setStorageSync('parent_id', options.parent_id)
				// 如果用户从分享的小程序卡片点击进来的,设置一个url缓存,登录后返回当前缓存url
				let pages = getCurrentPages();
				let curPage = pages[pages.length - 1];
				uni.setStorageSync('newurl', curPage.$page.fullPath)
				this.$u.api.binding_refer({
					id: options.parent_id
				}).catch(() => {
					console.log('接口报错：绑定失败')
					// uni.showToast({
					// 	icon: 'none',
					// 	title: '绑定失败'
					// })
				})
			}
			this.getStoreTeam()
		},
		methods: {
			getStoreTeam() {
				this.$u.api.StylistList({
					page: this.page,
					store_id: uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo'))
						.store_id : 1
				}).then(res => {
					let user_id = uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo'))
						.user_id : 0
					this.$u.mpShare = {
						title: '团队风采',
						path: '/merchant/store-team/store-team?parent_id=' + user_id
					}
					this.show = true
					this.isLoading = false
					if (res.datas.length) {
						res.datas.forEach(item => {
							this.storeTeam.push(item)
						})
					} else {
						this.noMore = true
					}
				})
			},
			goTeamInfo(stylist_id) {
				uni.navigateTo({
					animationDuration: 500,
					url: '/merchant/store-team/store-team-info?stylist_id=' + stylist_id
				})
			}
		},
		onReachBottom() {
			if (!this.noMore) {
				this.page++
				this.isLoading = true
				this.getStoreTeam()
			}
		}
	}
</script>

<style lang="scss">
	.store-team-list {
		padding: 30rpx;
	}
</style>